import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class UsedStoreZservice {

  serviceUrls: any = {
    dictUrl: '/dict/detail', // 字典查询
    dictSubsidyUrl: '/dict/details', // 字典查询(补贴规则)
    uploadFileUrl: '/common/upload/file', // 上传

    queryMallOrderListUrl: '/mallOrder/list', // 二手订单管理列表
    queryMallOrderDetailsUrl: '/mallOrder/details', // 二手订单管理详情
    examineOrderUrl: '/mallOrder/deliverGoods', // 二手订单审核
    orderExportUrl: '/mallOrder/getOrderExcel', // 二手订单导出
    refundSalesUrl: '/mallOrder/mallOrderRefund', // 二手订单售后退款

    recycleLibraryListUrl: '/recycleLibrary/list', // 库位列表查询
    saveRecycleLibraryUrl: '/recycleLibrary/save', // 库位添加
    updateRecycleLibraryUrl: '/recycleLibrary/update', // 库位编辑

    querySupplierListUrl: '/supplier/list', // 查询货主
    querySplitAccountListUrl: '/mallOrder/splitAccount', // 查询订单分账List
    updateSeparateUrl: '/mallOrder/separate', // 订单分账操作
    revokeSeparateUrl: '/mallOrder/revokeSeparate', // 撤销分账操作

    queryOutStoreDetailUrl: '/recycleDelivery/details', // 出库单详情(销售信息详情)
    updateOutOrderDetailUrl: '/recycleDelivery/update' // 修改销售信息

  };

  constructor(public httpClient: HttpClient) { }
  
  // 二手订单--列表查询
  queryMallOrderList(params: any) {
    return this.httpClient.post(this.serviceUrls.queryMallOrderListUrl, params).toPromise();
  }

  // 二手订单--审核
  examineOrderData(params: any) {
    return this.httpClient.post(this.serviceUrls.examineOrderUrl, params).toPromise();
  }

  // 二手订单--导出
  orderExportData(params: any) {
    return this.httpClient.get(this.serviceUrls.orderExportUrl, { params });
  }

  // 二手订单--详情
  queryMallOrderDetails(params: any) {
    return this.httpClient.post(this.serviceUrls.queryMallOrderDetailsUrl, params).toPromise();
  }

  // 二手订单-售后退款
  refundSalesData(params: any) {
    return this.httpClient.post(this.serviceUrls.refundSalesUrl, params).toPromise();
  }

  /**
   * 查询库位list
   * @param params 
   * @returns 
   */
  recycleLibraryList(params: any) {
    return this.httpClient.post(this.serviceUrls.recycleLibraryListUrl, params).toPromise();
  }

  /**
   * 库位添加
   * @param params 
   * @returns 
   */
  saveRecycleLibrary(params: any) {
    return this.httpClient.post(this.serviceUrls.saveRecycleLibraryUrl, params).toPromise();
  }

  /**
   * 库位修改
   * @param params 
   * @returns 
   */
  updateRecycleLibrary(params: any) {
    return this.httpClient.post(this.serviceUrls.updateRecycleLibraryUrl, params).toPromise();
  }

  /**
   * 字典查询
   * @param parentKey 
   * @returns 
   */
  dictListData(parentKey: any) {
    let params: any = {
      parentKey: parentKey,
      pageNum: 0,
      pageSize: 0
    };
    return this.httpClient.get(this.serviceUrls.dictUrl, { params: params }).toPromise();
  }

  // 字典查询 补贴规则
  getSubsidyRuleData(key: string) {
    let params = {
      key
    }
    return this.httpClient.get(this.serviceUrls.dictSubsidyUrl, { params }).toPromise();
  }

  /**
   * 文件上传
   * @param fileToUpload 
   * @returns 
   */
  uploadFileData(fileToUpload: File) {
    const formData: FormData = new FormData();
    formData.append('file', fileToUpload);
    formData.append('name', "love-recyc");
    return this.httpClient.post(this.serviceUrls.uploadFileUrl, formData).toPromise();
  }

  // 查询货主(供货商)
  querySupplierList(params: any) {
    return this.httpClient.post(this.serviceUrls.querySupplierListUrl, params).toPromise();
  }

  /**
   * ----------------------------------------------------------------
   * 订单分账
   * ----------------------------------------------------------------
   */

  // 查询订单分账列表List
  querySplitAccountList(params: any) {
    return this.httpClient.post(this.serviceUrls.querySplitAccountListUrl, params).toPromise();
  }

  // 订单分账操作
  updateSeparateItem(params: any) {
    return this.httpClient.post(this.serviceUrls.updateSeparateUrl, params).toPromise();
  }

  // 撤销订单分账操作
  revokeSeparateItem(params: any) {
    return this.httpClient.post(this.serviceUrls.revokeSeparateUrl, params).toPromise();
  }

  /**
   * ----------------------------------------------------------------
   * 出库单销售信息
   * ----------------------------------------------------------------
   */

  // 详情
  queryOutStoreDetail(params: any) {
    return this.httpClient.post(this.serviceUrls.queryOutStoreDetailUrl, params).toPromise();
  }

  // 修改
  updateOutOrderDetail(params: any) {
    return this.httpClient.post(this.serviceUrls.updateOutOrderDetailUrl, params).toPromise();
  }
}



